package org.dormi.learn.pojo;

import org.dormi.learn.utils.JsonSerializer;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * 包含 _dirty标志, 和扩展 props
 *
 * @author : dormi330
 * @version : 1.0
 */
public class ExtensibleTenantEO extends BaseEO {

    private Long tenantId;
    private Integer version;
    private LocalDateTime createdTime;
    private LocalDateTime updatedTime;
    private Long createdBy;
    private Long updatedBy;
    private String remark;
    private Integer enabled;

    /* props */
    /* props */
    /* props */
    /** 扩展属性存放在这里, 序列化成json */
    private Map<String, String> props;

    public void addProp(String key, String value) {
        if (props == null) {
            props = new HashMap<>(5);
        }
        props.put(key, value);
        _markDirty();
    }

    public String getProp(String name) {
        return props == null ? null : props.get(name);
    }

    public String mapToJson() {
        if (props == null) {
            return null;
        }
        return JsonSerializer.toJson(props);
    }

    /* === _dirty === */
    /* === _dirty === */
    /* === _dirty === */
    private boolean _dirty;

    public final void _markDirty() {
        this._dirty = true;
    }

    public final void _cleanDirty() {
        this._dirty = false;
    }

    public final boolean _dirty() {
        return _dirty;
    }

    /* === set/get === */
    /* === set/get === */
    /* === set/get === */

}
